﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AnalysisServices.AdomdClient;

namespace Moop.DataLayer.Olap.Service.Test
{

    [TestClass]
    public class NullOnColsUnitTest
    {
        public string CONN_STRING = @"Data Source=.;Catalog=Adventure Works DW 2008R2;";
        public string m_MdxNullOnColsCommand = @"SELECT {[Customer].[Customer].MEMBERS} ON 0 FROM [Adventure Works]";
        public string m_MdxNullOnColsCommand2 = @"SELECT {} ON 0, {[Customer].[Customer].MEMBERS} ON 1 FROM [Adventure Works]";

        public NullOnColsUnitTest()
        {
        }

        [TestMethod]
        public void NullOnColsTest()
        {
            StringBuilder result = new StringBuilder();

            #region Fetch Data via Execute CellSet

            result.Clear(); //Clear SB

            using (AdomdConnection conn = new AdomdConnection(CONN_STRING))
            {
                try
                {
                    conn.Open();

                    AdomdCommand cmd = new AdomdCommand(m_MdxNullOnColsCommand2, conn);
                    CellSet cellSetResult = cmd.ExecuteCellSet();
                    TupleCollection tuplesOnColumns = cellSetResult.Axes[0].Set.Tuples;

                    foreach (Microsoft.AnalysisServices.AdomdClient.Tuple column in tuplesOnColumns)
                    {
                        result.Append(column.Members[0].Caption + "\t");

                    }

                    conn.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
                }                
            }

            #endregion
        }
    }
}
